package pincipal.pack;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class PesoEspecifico extends Activity {
	
	private TextView pesoEspecifico;
	private TextView pesoTotal;
	private TextView labelResultados;
	private TextView labelPesoTotal;
	private Button volverMenuPrincipal;
	private EditText diametro;
	private EditText medidaHorizontales;
	private EditText numeroHorizontales;
	DecimalFormat df = new DecimalFormat("0.00");	
	private Button calcular;
	private String[] medidas = new String[]{"mm", "cm", "mt"};
	
	
	@Override
	public void onCreate(Bundle b)
	{
		super.onCreate(b);
		requestWindowFeature( Window.FEATURE_NO_TITLE );
		setContentView(R.layout.peso_especifico);
		
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		this.volverMenuPrincipal = (Button)findViewById(R.id.menuPrincipal);
		this.volverMenuPrincipal.setBackgroundResource(R.drawable.home);
		this.labelResultados = (TextView)findViewById(R.id.labelResultados);
		this.labelPesoTotal = (TextView)findViewById(R.id.labelPesoTotal);
		this.diametro = (EditText)findViewById(R.id.diametro);
		this.medidaHorizontales = (EditText)findViewById(R.id.horizontales);
		this.numeroHorizontales = (EditText)findViewById(R.id.numeroHorizontales);		
		this.pesoEspecifico = (TextView)findViewById(R.id.pesoEspecifico);	
		this.pesoTotal = (TextView)findViewById(R.id.pesoTotal);	
		this.calcular = (Button)findViewById(R.id.calcular);
		
		this.calcular.setOnClickListener( new OnClickListener()
		{

			public void onClick(View arg0) 
			{
				if ( diametro.getText().toString().equals("")  ||
						medidaHorizontales.getText().toString().equals("") ||
						numeroHorizontales.getText().toString().equals(""))
				{
					Toast.makeText(PesoEspecifico.this, "Debe ingresar todos los datos", Toast.LENGTH_SHORT).show();
				}
				
				else
				{
					pesoEspecifico.setText(String.valueOf(calcularPesoEespecifico()) + " kg");
					pesoTotal.setText(String.valueOf(calularPesoTotal()) + " kg");
				}
			}
			
		}
		);
		
		this.volverMenuPrincipal = (Button)findViewById(R.id.menuPrincipal);
		this.volverMenuPrincipal.setOnClickListener( new OnClickListener()
        {
        	public void onClick(View v)
        	{
        		Intent intent = new Intent(PesoEspecifico.this, CubicMagic.class);
        		startActivity(intent);
        	}
        	
        });
		
	}

	private String calcularPesoEespecifico()
	{
		double diam = Double.parseDouble(diametro.getText().toString());
		
		double peso = ( (diam*diam)*6.17 ) / 1000;
		
		return df.format(peso);
	}
	
	private String calularPesoTotal()
	{
		double nroHorizontales = Double.parseDouble(this.numeroHorizontales.getText().toString());
		double medHorizontales = Double.parseDouble(this.medidaHorizontales.getText().toString());	
		double total = nroHorizontales*medHorizontales* Double.parseDouble(calcularPesoEespecifico());
		return df.format(total);
	}
	

}
